<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('管理')"/>
</head>
<body>
<div class="wrapper">
    <form style="font-size: 12px" id="form">
        <div class="box-body">
            <div class="form-group">
                <label>激活码</label>
                <input type="text" class="form-control input-sm" name="code" id="code" required>
            </div>
            <div class="form-group">
                <label>类别</label>
                <input type="text" class="form-control input-sm" name="type" id="type" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = "/car/code";
    $(function () {
        f();
    });
    function f() {
        $('#form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                code: {
                    message: '激活码验证失败',
                    validators: {
                        notEmpty: {
                            message: '激活码不能为空'
                        },
                        remote: {
                            url: prefix + "/verify",
                            message: '激活码已存在,请重新输入',
                            delay: 1000,
                            type: 'POST',
                            data: function (validator) {
                                return {
                                    code: $("input[name=code]").val(),
                                    method: "code"
                                };
                            }
                        }
                    }
                },
                type: {
                    validators: {
                        notEmpty: {
                            message: '激活码类型不能为空'
                        }
                    }
                }
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            var json = $.common.formToJSON('form');
            console.log(json);
            $.operate.save(prefix + '/save', json);
        }
    }
</script>
</body>
</html>
